import type { IColumnsOption } from 'vc';
import { INDEX, COMPANY_NAME, BUSINESS_DATA, REGISTERED_CAPITAL, PROVINCE, CITY, COUNTRY, INDUSTRY_CATEGORY, INFO_SOURCE, CellRenderMap, TAG_YEAR } from '@/utils/tableColumn';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    { ...INDEX },
    {
      width: 230,
      title: '矿山名称',
      field: 'otherCompanyName',
      slots: {
        default({ row, column }) {
          const content = row.highlight?.otherCompanyName ? row.highlight?.otherCompanyName : row[column.field];
          return <span title={row[column.field] || ''} v-html={content || '-'}></span>;
        }
      }
    },
    {
      width: 100,
      align: 'center',
      title: '披露日期',
      field: 'noticeDate',
      sortable: true
    },
    {
      ...INFO_SOURCE('tagName')
    },
    {
      width: 120,
      title: '认定级别',
      field: 'levelCode',
      sortable: true
    },
    {
      ...TAG_YEAR,
      field: 'statisticalYear',
      sortable: true
    },
    {
      width: 150,
      title: '认定单位',
      field: 'dataSource',
      sortable: true
    },
    {
      ...COMPANY_NAME,
      field: 'companyName',
      fixed: null,
      title: '采矿权人'
    },
    {
      width: 220,
      title: '采矿许可证号',
      field: 'licenseNumber',
      align: 'center',
      sortable: true,
      slots: {
        default({ row }) {
          return <span v-html={row?.licenseNumber || '-'}></span>;
        }
      }
    },
    {
      width: 100,
      title: '发证日期',
      field: 'issuingDate',
      align: 'center',
      sortable: true,
      slots: {
        default({ row }) {
          return <span v-html={row?.issuingDate || '-'}></span>;
        }
      }
    },
    {
      width: 100,
      title: '采矿矿种',
      field: 'oreType',
      sortable: true,
      slots: {
        default({ row }) {
          return <span v-html={row?.oreType || '-'}></span>;
        }
      }
    },
    {
      width: 120,
      title: '生产规模',
      field: 'productionScale',
      sortable: true,
      slots: {
        default({ row }) {
          return <span v-html={row?.productionScale || '-'}></span>;
        }
      }
    },
    {
      width: 150,
      title: '矿区面积',
      field: 'area',
      sortable: true,
      slots: {
        default({ row }) {
          return <span v-html={row?.area || '-'}></span>;
        }
      }
    },
    {
      width: 180,
      title: '有效起止日期',
      align: 'center',
      sortable: true,
      formatter({ row }) {
        return !row.startDate && !row.expireDate ? '-' : `${row.startDate || '-'} 至 ${row.expireDate || '-'}`;
      }
    },
    { ...PROVINCE },
    { ...CITY },
    { ...COUNTRY },
    { ...INDUSTRY_CATEGORY },
    { ...BUSINESS_DATA },
    { ...REGISTERED_CAPITAL }
  ]);

  return {
    columns
  };
}
